import os

from flask import Flask
from flask_cors import CORS

from aiapp import views
from aiapp import setting, utils

logger = setting.log_config.logger
redisUtils = utils.redis_util.redisClient()

current_dir = os.path.dirname(os.path.abspath(__file__))

app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False
urlPrefix = '/kngu/'

app.register_blueprint(views.home_controller.bp, url_prefix=urlPrefix)
app.register_blueprint(views.login_controller.bp, url_prefix=urlPrefix + 'login/')

rules = [str(p) for p in app.url_map.iter_rules()]

logger.info(f"可用的访问路由: rules = 【{rules}】")


@app.errorhandler(Exception)
def all_exception_handler(e):
    pass


# 解决跨域问题
# CORS(app , supports_credentials = True)
CORS(app)


@app.before_request
def first_request():
    """
    请求记录
    :return:
    """
    pass


if __name__ == '__main__':
    port = 8080
    app.run(host="0.0.0.0", port=port, threaded=True)
